{% extends "base/base_site.html" %}
{% block content %}
<div class="dataTables_wrapper border-bottom">
        <div class="row">
            <div class="col-lg-6">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>命令行</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="#">选项 1</a>
                                </li>
                                <li><a href="#">选项 2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-4">
                                <div class="dataTables_length" id="DataTables_Table_0_length"
                                     style="margin-bottom:15px;">
                                    <input type="text" placeholder="搜索: IP、服务、项目" id="search"
                                           class="form-control input-sm">
                                </div>
                            </div>
                        </div>

                        <div class="table-responsive">
                            <form class="form-horizontal cmd_from">

                                <table class="table table-striped table-bordered table-hover dataTables-example">
                                    <thead>
                                    <tr>
                                        <th width="20"><input type="checkbox" id="CheckedAll"></th>
                                        <th>IP</th>
                                        <th>服务名称</th>
                                        <th>平台名称</th>

                                    </tr>
                                    </thead>
                                    <tbody>

                                    {% for   row   in   server_list %}

                                        <tr class="gradeA" id="{{ row.id }}">
                                            <td><input type="checkbox" value="{{ row.id }}" name="id"></td>
                                            <td class="center">{{ row.in_ip }}</td>
                                            <td class="center">{{ row.app_project.app_name_en }}</td>
                                            <td class="center">{{ row.app_project.platform.name }} </td>
                                        </tr>
                                    {% endfor %}

                                    </tbody>
                                </table>

                                <div class="ibox-content">
                                    <div class="form-group"><label class="col-sm-2 control-label">命令</label>

                                        <div class="col-lg-8 col-sm-9"><input type="text" class="form-control" placeholder="命令" name="cmd" required=""><span class="help-block m-b-none"></span>
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <div class="col-sm-6 col-sm-offset-2">

                                            <a id="cmd" class="btn btn-primary" type="submit" onclick='submitLinux()'>提交</a>
                                            <button class="btn btn-white" type="button" onclick='clearBody()'>取消
                                            </button>
                                        </div>
                                    </div>

                                </div>

                            </form>
                        </div>

                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>输出结果
                        </h5>
                        <div class="ibox-tools">
                            <a class="collapse-links">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="#">配置选项 1</a>
                                </li>
                                <li><a href="#">配置选项 2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content  pres"   >

                          <pre> <span id="err"></span></pre>

                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block javascripts %}
    {{ block.super }}
<script>
{#    $(function () {#}
{#        $('#cmd').click(function () {#}
function submitLinux() {
{#    alert('aa')#}
{#    alert($('.cmd_from').serialize())#}
            $.ajax({
                url: "/tasks/cmd/",
                type: 'POST',
                data: $('.cmd_from').serialize(),
                success: function (data) {
                    var obj = JSON.parse(data);
                    cons = "";
                    if (obj.data) {
                         $.each(obj, function (data, values) {
                            $.each(values, function (index, value) {
                                cons += "<pre>"+"主机:" + value.ip + "\n" + "结果: \n " + value.data + "</pre>"

                            });
                            $(".pres").html(cons); //把内容入到这个div中即完成
                        });
                    } else {
                        $('#err').text(obj.error);
                    }
                }
            })
    }
{#        });#}
{##}
{#    });#}
    function clearBody() {
        location.reload()
    }
</script>

{% endblock %}